package com.cumt.threeway.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.cumt.threeway.R;
import com.cumt.threeway.model.Pinglun;
import com.cumt.threeway.model.Single;
import com.cumt.threeway.util.ThreeWayUtil;

import java.util.List;

/**
 * Created by 胡晶晶 on 2016/5/22.
 */
public class CommentAdapter extends BaseAdapter {

    private List<Pinglun> mList;
    private Context mContext;

    public CommentAdapter(List<Pinglun> list, Context context) {
        mContext = context;
        mList = list;
    }

    @Override
    public int getCount() {
        return mList.size();
    }

    @Override
    public Object getItem(int position) {
        return mList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.comment_ite, null);
            viewHolder = new ViewHolder();
            viewHolder.mTvName = (TextView) convertView.findViewById(R.id.tv_pinglun_username);
            viewHolder.mTvDate = (TextView) convertView.findViewById(R.id.tv_pinglun_shijian);
            viewHolder.mTvContent = (TextView) convertView.findViewById(R.id.tv_pinglun_content);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Pinglun activities = mList.get(position);
        if("QQ".equals(activities.getTel()) || "SinaWeibo".equals(activities.getTel())) {
            viewHolder.mTvName.setText(ThreeWayUtil.getInstance().getUserName(mContext));
        } else {
            String tel3 = activities.getTel().substring(0,3);
            String tel12 = activities.getTel().substring(8,11);
            viewHolder.mTvName.setText(tel3 + "****" + tel12);
        }
        viewHolder.mTvDate.setText(activities.getDate());
        viewHolder.mTvContent.setText(activities.getContent());
        return convertView;
    }

    class ViewHolder {
        private TextView mTvName;
        private TextView mTvDate;
        private TextView mTvContent;
    }
}
